<?php

class ModalConfirm {
	
	public $id;
	public $titel;
	public $content;
	public $confirmButton;
	public $linkIds;
	public $action;
	public $cancelText;
	
	public function ModalConfirm($titel,$content,$confirmButton,$linkIds,$action,$cancelText=null){
		$this->id = uniqid();
		$this->titel = $titel;
		$this->content = $content;
		$this->confirmButton = $confirmButton;
		$this->linkIds = $linkIds;
		$this->action = $action;
		if($cancelText==null){
			$cancelText="Cancel";
		}
		$this->cancelText = $cancelText;
	}
	
	public function getCode(){
		
		?>
		<script type="text/javascript">
			$(function() {
		<?php foreach($this->linkIds AS $linkId){	?>		
				$( '<?php echo $linkId ?>' ).click(function(){
					$( "#<?php echo $this->id; ?>" ).dialog( "open" );
					return false;
				});
		
		<?php } ?>
				
				$( "#<?php echo $this->id; ?>" ).dialog({
					resizable: false,
					modal: true,
					autoOpen: false,
					width: 500,
					buttons: {
						"<?php echo $this->confirmButton ?>": function() {
							<?php echo $this->action ?>;
						},
						"<?php echo $this->cancelText ?>": function() {
							$( this ).dialog( "close" );
						}
					}
				});
			});
		</script>
	  
		<div id="<?php echo $this->id ?>" title="<?php echo $this->titel ?>">
			<p><span class="ui-icon ui-icon-alert" style="float:left; margin:0 7px 20px 0;"></span><?php echo $this->content ?></p>
		</div>
    
		<?php 
	}
	
}

?>